package com.example.exercise.step.controller;

import com.example.exercise.common.BaseResponse;
import com.example.exercise.step.response.StepsRankAllResp;
import com.example.exercise.step.service.StepService;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("step")
public class StepController {

    @Resource
    private StepService stepService;

    //http://localhost:8080/step/getRankAll?begin=1&&pageSize=20
    @RequestMapping(value = "/getRankAll", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<List<StepsRankAllResp>> getRankAll(int begin, int pageSize) {
        BaseResponse<List<StepsRankAllResp>> baseResponse = new BaseResponse<>();
        List<StepsRankAllResp> list = stepService.getRankAll(begin, pageSize);
        if (list.isEmpty()) list = stepService.getRankAll(begin, pageSize);
        baseResponse.setCode(0);
        baseResponse.setMsg("返回数据成功");
        baseResponse.setData(list);
        return baseResponse;
    }

    //http://localhost:8080/step/getRankToday?begin=1&&pageSize=20
    @RequestMapping(value = "/getRankToday", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<List<StepsRankAllResp>> getRankToday(int begin, int pageSize) {
        BaseResponse<List<StepsRankAllResp>> baseResponse = new BaseResponse<>();
        List<StepsRankAllResp> list = stepService.getRankToday(begin, pageSize);
        if (list.isEmpty()) list = stepService.getRankAll(begin, pageSize);
        baseResponse.setCode(0);
        baseResponse.setMsg("返回数据成功");
        baseResponse.setData(list);
        return baseResponse;
    }
}
